// JavaScript Document

Ext.onReady(function() {

	Ext.BLANK_IMAGE_URL = 'img/s.gif';

	Ext.QuickTips.init();

	var auth = new Ext.form.FormPanel({
		region: 'center',
		margins:'3 3 3 3',
		standardSubmit: true,
		labelWidth: 50,
		frame: true,
		labelPad: 10,
		defaultType: 'radio',
//		autoHeight: true,
//		height: 300,

		defaults: {
			msgTarget: 'side'
		},
		keys: [{
			key: Ext.EventObject.ENTER,
			fn: function() {
				selectHandler();
			}
		}],
		items: [
                    new Ext.form.ComboBox({
                        mode: 'local',
                        name: 'module',
                        store: new Ext.data.ArrayStore({
                            fields: [ 'modId', 'ModName' ],
                            data: [['AdminForm', 'AdminForm'], ['MainForm', 'MainForm']]
                        }),
                        valueField: 'modId',
                        displayField: 'ModName'
                    })
                ]
	});

	var logo = new Ext.Panel({
		region: 'west',
		width: 60,
		frame: false,
		border: false,
		bodyStyle: 'background: url(img/gpg-icon.png) center no-repeat;',
		margins:'3 0 3 3',
		cmargins:'3 3 3 3'
	});

	var selectHandler = function() {
		if (auth.getForm().isValid())
			auth.getForm().submit();
	};

	var win = new Ext.Window({
		title: 'Выбор модуля',
		resizable: false,
		closable: false,
		width: 323,
		height: 135,
		layout: 'border',
		items: [logo, auth],
		buttons: [{
			text: 'Выбрать',
			handler: selectHandler
		}]
	});

	if (error != '') {

		Ext.Msg.show({
			title:'Ошибка авторизации',
			msg: error,
			buttons: Ext.Msg.OK,
			icon: Ext.MessageBox.ERROR,
			fn: function() {
				win.show();
			}
		});

	} else {
		win.show();
	}

});